package com.ita.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import com.ita.pojo.MUser;
import com.ita.util.MD5Util;


@Component
@Aspect
public class CheckAspect {
	
//	private final String RESGITER = "execution(* service.UserService.resigter(pojo.Cuser))";
//	private final String LOGIN = "execution(* service.UserService.login(pojo.Cuser))";

	@Pointcut("@annotation(com.ita.annotation.Login)")
	public void loginAspect() {

	}

	@Pointcut("@annotation(com.ita.annotation.Register)")
	public void registerAspect() {
	}
	


	@Around("loginAspect()")
	public Object loginAround(ProceedingJoinPoint point) {

		// String password = MD5Util.getInstance().makeMD5((String)
		// point.getArgs()[1]);

		String name = (String) point.getArgs()[0];
		String pwd = (String) point.getArgs()[1];
		Object o = null;
		System.out.println("log around before..");

		try {
	
			o = point.proceed(new Object[] { name,MD5Util.makeMD5(pwd) });

		} catch (Throwable e) {
			e.printStackTrace();
		}

	
		return o;
	}

	@Around("registerAspect()")
	public Object resgiterAround(ProceedingJoinPoint point) {
		MUser muser = (MUser) point.getArgs()[0];
		Object o = null;
	
		try {
			
			muser.setPwd((MD5Util.makeMD5(muser.getPwd())));
			o = point.proceed(new Object[] { muser });

		} catch (Throwable e) {
			e.printStackTrace();
		}

		return o;
	}


}
